﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HNQXYJ.BLL;
using HNQXYJ.Model;

namespace HNQXYJ.HN_User
{
    public partial class UserUpdate : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                int id = Convert.ToInt32(Request["id"]);
                Users user = new Users();
                user = new UsersBLL().GetUserDataById(id);
                this.txtUserName.Text = user.UserName;
                this.txtTrueName.Text = user.TrueName;
                this.txtTouchMehtod.Text = user.TouchMethod;
                this.txtNotes.Text = user.Notes;
               

            }
        }

        //返回用户管理页面
        protected void reset_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect("UserMgr.aspx");
        }

        //更新用户数据
        protected void add_Click(object sender, ImageClickEventArgs e)
        {
            int id = Convert.ToInt32(Request["id"]);
            Users user = new Users();
            user.ID = id;
            user.UserName = this.txtUserName.Text;
            user.TrueName = this.txtTrueName.Text.Trim();
            //省级权限
            if (this.HidCity.Value == "")
            {
                user.RankName = "河南省";
                user.RankLevel = "henansheng";
            }
            //市级权限
            if (this.HidCity.Value != "" && this.HidCounty.Value == "")
            {
                user.RankName = this.cityName.Value;
                user.RankLevel = this.HidCity.Value;
            }
            //县级权限
            if (this.HidCity.Value != "" && this.HidCounty.Value != "")
            {
                user.RankName = this.cityName.Value + this.countyName.Value;
                user.RankLevel = this.HidCounty.Value;

            }
            user.TouchMethod = this.txtTouchMehtod.Text;
            user.Notes = this.txtNotes.Text;
            bool flage = new UsersBLL().UpdateUserById(user);
            if (flage)
            {
                Response.Redirect("UserMgr.aspx");
            }

        }
    }
}